package com.cyd.demo5.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author keyer
 * @Description : 描述
 * Created by cyd on 2021-05-14 15:35:38
 */
@WebFilter(urlPatterns = "/*")
public class OneFilter implements Filter {

    int maxAge = 60;

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        String age = request.getParameter("age");
        if (age != null && Integer.parseInt(age) < maxAge) {
            chain.doFilter(request, response);
        } else {
            response.setContentType("text/html;charset=utf-8");
            PrintWriter out = response.getWriter();
            out.print("<h1>年龄太大，不适宜访问<h1>");
        }
    }
}
